
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    JEuler.system.loadJS("data/102.dat");
    JEuler.system.printCaption("102");
    JEuler.system.startTimerCount();
    
    //(yb-ya)*(x-xa) = (xb-xa)*(y-ya)
    //y = ya + [(yb-ya)/(xb-xa)]*(x-xa)
    
    var test = function(xa,ya,xb,yb) {
        var y;
        if((xa>=0 && xb<=0) || (xa<=0 && xb>=0)) {
            y = ya + [(yb-ya)/(xb-xa)]*(0-xa);
            if(y>0) return 1;
            if(y<0) return -1;
        }
        return 0;
    }
    
    var t1, t2, t3, count=0;
    for(var i=0; i<records.length; i++) {
        var x=records[i];
        t1 = test(x[0],x[1],x[2],x[3]);
        t2 = test(x[2],x[3],x[4],x[5]);
        t3 = test(x[4],x[5],x[0],x[1]);
        if((t1+t2+t3==0) && (Math.abs(t1)+Math.abs(t2)+Math.abs(t3)==2)) {
            count++;
        }
    }


    JEuler.system.print("SUM=" + count);
    JEuler.system.printTimerCount();
    
})();
